package com.anc.admin.model.admin.hanlder;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author amos
 * @since 2022/4/12 0012 14:48
 */
@Component
public class XsyHandlerContext implements ApplicationContextAware, InitializingBean
{
    private ApplicationContext applicationContext;

    public static Map<String, XsyHandler> EXPORT_HANDLER_MAP = new HashMap<>();

    @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
    {
        this.applicationContext = applicationContext;
    }

    public XsyHandler getExportHandler(String taskName)
    {
        return EXPORT_HANDLER_MAP.get(taskName);
    }

    @Override public void afterPropertiesSet() throws Exception
    {
        applicationContext.getBeansOfType(XsyHandler.class).values().forEach(n -> EXPORT_HANDLER_MAP.put(n.getFlog(), n));
    }
}
